package com.sekill.miaosha.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sekill.miaosha.entity.TbStock;
import com.sekill.miaosha.mapper.TbStockMapper;
import com.sekill.miaosha.service.ITbStockService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 库存表，代表库存，秒杀库存等信息 服务实现类
 * </p>
 *
 * @author gao
 * @since 2021-06-18
 */
@Service
public class TbStockServiceImpl extends ServiceImpl<TbStockMapper, TbStock> implements ITbStockService {

    @Autowired
    TbStockMapper tbStockMapper;

    @Autowired
    RedisTemplate redisTemplate;


    @Override
    public int savetbstock(TbStock tbStock) {

        return 0;
    }

    @Override
    public boolean stockItem(Long skuId, Integer userId) {

        Boolean result=false;

        int updatestock = tbStockMapper.updatestock(skuId);

        if(updatestock>0){

            result=true;
        }

        Map<String, Object> map = new HashMap<>();
        List<TbStock> tbStocks = tbStockMapper.selectstockByName(map, new RowBounds(0, 10));

        for (TbStock tbStock : tbStocks) {
            System.out.println(tbStock);
        }

        return result;
    }

    @Override
    public TbStock findbyskuid(Long skuid) {
        return tbStockMapper.findbyskuid(skuid);
    }

    @Override
    public int updatestock(Long id) {
        return tbStockMapper.updatestock(id);
    }
}
